﻿<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type='text/xsl' href="scriptsql.xsl"?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database includeDrop="true">SecurityFoundationDB</database>
<procedures>
		
		<procedure owner="dbo" name="uspRealm_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Realm table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[RealmID],
					[Realm],
					[AuthenticationProviderName],
					[RoleProviderName],
					[TokenLife],
					[AdminApplication]
				FROM
					[dbo].[Realm]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspRealm_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Realm table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [RealmID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([RealmID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [RealmID]'
				SET @SQL = @SQL + ' FROM [dbo].[Realm]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[RealmID], O.[Realm], O.[AuthenticationProviderName], O.[RoleProviderName], O.[TokenLife], O.[AdminApplication]
				FROM
				    [dbo].[Realm] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[RealmID] = PageIndex.[RealmID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Realm]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspRealm_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Realm table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RealmId" type="uniqueidentifier" direction="Output" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@Realm" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@AuthenticationProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@RoleProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@TokenLife" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@AdminApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[Realm]
					(
					[RealmID]
					,[Realm]
					,[AuthenticationProviderName]
					,[RoleProviderName]
					,[TokenLife]
					,[AdminApplication]
					)
				VALUES
					(
					@RealmId
					,@Realm
					,@AuthenticationProviderName
					,@RoleProviderName
					,@TokenLife
					,@AdminApplication
					)
				
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspRealm_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Realm table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RealmId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@OriginalRealmId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@Realm" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@AuthenticationProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@RoleProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@TokenLife" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@AdminApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Realm]
				SET
					[RealmID] = @RealmId
					,[Realm] = @Realm
					,[AuthenticationProviderName] = @AuthenticationProviderName
					,[RoleProviderName] = @RoleProviderName
					,[TokenLife] = @TokenLife
					,[AdminApplication] = @AdminApplication
				WHERE
[RealmID] = @OriginalRealmId 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspRealm_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Realm table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RealmId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[Realm] WITH (ROWLOCK) 
				WHERE
					[RealmID] = @RealmId
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspRealm_GetByRealmId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Realm table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RealmId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[RealmID],
					[Realm],
					[AuthenticationProviderName],
					[RoleProviderName],
					[TokenLife],
					[AdminApplication]
				FROM
					[dbo].[Realm]
				WHERE
					[RealmID] = @RealmId
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspRealm_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Realm table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@RealmId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@Realm" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@AuthenticationProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@RoleProviderName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@TokenLife" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@AdminApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [RealmID]
	, [Realm]
	, [AuthenticationProviderName]
	, [RoleProviderName]
	, [TokenLife]
	, [AdminApplication]
    FROM
	[dbo].[Realm]
    WHERE 
	 ([RealmID] = @RealmId OR @RealmId IS NULL)
	AND ([Realm] = @Realm OR @Realm IS NULL)
	AND ([AuthenticationProviderName] = @AuthenticationProviderName OR @AuthenticationProviderName IS NULL)
	AND ([RoleProviderName] = @RoleProviderName OR @RoleProviderName IS NULL)
	AND ([TokenLife] = @TokenLife OR @TokenLife IS NULL)
	AND ([AdminApplication] = @AdminApplication OR @AdminApplication IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [RealmID]
	, [Realm]
	, [AuthenticationProviderName]
	, [RoleProviderName]
	, [TokenLife]
	, [AdminApplication]
    FROM
	[dbo].[Realm]
    WHERE 
	 ([RealmID] = @RealmId AND @RealmId is not null)
	OR ([Realm] = @Realm AND @Realm is not null)
	OR ([AuthenticationProviderName] = @AuthenticationProviderName AND @AuthenticationProviderName is not null)
	OR ([RoleProviderName] = @RoleProviderName AND @RoleProviderName is not null)
	OR ([TokenLife] = @TokenLife AND @TokenLife is not null)
	OR ([AdminApplication] = @AdminApplication AND @AdminApplication is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspRealm_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Realm table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [RealmID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [RealmID] )
				SELECT TOP {3} [RealmID]
				FROM [dbo].[Realm] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[RealmID], O.[Realm], O.[AuthenticationProviderName], O.[RoleProviderName], O.[TokenLife], O.[AdminApplication]
				FROM
				    [dbo].[Realm] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[RealmID] = PageIndex.[RealmID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[Realm] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspApplicationDefination_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the ApplicationDefination table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[ApplicationKey],
					[ApplicationName],
					[Realm],
					[ObjectSecurity],
					[FieldLevelSecurity],
					[OwnerRole],
					[ApplicationType],
					[UseRealmRole]
				FROM
					[dbo].[ApplicationDefination]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspApplicationDefination_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ApplicationDefination table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ApplicationKey] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([ApplicationKey])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [ApplicationKey]'
				SET @SQL = @SQL + ' FROM [dbo].[ApplicationDefination]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[ApplicationKey], O.[ApplicationName], O.[Realm], O.[ObjectSecurity], O.[FieldLevelSecurity], O.[OwnerRole], O.[ApplicationType], O.[UseRealmRole]
				FROM
				    [dbo].[ApplicationDefination] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[ApplicationKey] = PageIndex.[ApplicationKey]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[ApplicationDefination]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspApplicationDefination_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the ApplicationDefination table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Output" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ApplicationName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationType" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@UseRealmRole" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[ApplicationDefination]
					(
					[ApplicationKey]
					,[ApplicationName]
					,[Realm]
					,[ObjectSecurity]
					,[FieldLevelSecurity]
					,[OwnerRole]
					,[ApplicationType]
					,[UseRealmRole]
					)
				VALUES
					(
					@ApplicationKey
					,@ApplicationName
					,@Realm
					,@ObjectSecurity
					,@FieldLevelSecurity
					,@OwnerRole
					,@ApplicationType
					,@UseRealmRole
					)
				
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationDefination_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the ApplicationDefination table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@OriginalApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ApplicationName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationType" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@UseRealmRole" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[ApplicationDefination]
				SET
					[ApplicationKey] = @ApplicationKey
					,[ApplicationName] = @ApplicationName
					,[Realm] = @Realm
					,[ObjectSecurity] = @ObjectSecurity
					,[FieldLevelSecurity] = @FieldLevelSecurity
					,[OwnerRole] = @OwnerRole
					,[ApplicationType] = @ApplicationType
					,[UseRealmRole] = @UseRealmRole
				WHERE
[ApplicationKey] = @OriginalApplicationKey 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationDefination_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the ApplicationDefination table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[ApplicationDefination] WITH (ROWLOCK) 
				WHERE
					[ApplicationKey] = @ApplicationKey
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationDefination_GetByRealm" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ApplicationDefination table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[ApplicationKey],
					[ApplicationName],
					[Realm],
					[ObjectSecurity],
					[FieldLevelSecurity],
					[OwnerRole],
					[ApplicationType],
					[UseRealmRole]
				FROM
					[dbo].[ApplicationDefination]
				WHERE
					[Realm] = @Realm
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationDefination_GetByApplicationKey" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ApplicationDefination table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[ApplicationKey],
					[ApplicationName],
					[Realm],
					[ObjectSecurity],
					[FieldLevelSecurity],
					[OwnerRole],
					[ApplicationType],
					[UseRealmRole]
				FROM
					[dbo].[ApplicationDefination]
				WHERE
					[ApplicationKey] = @ApplicationKey
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspApplicationDefination_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the ApplicationDefination table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@ApplicationName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@ApplicationType" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@UseRealmRole" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ApplicationKey]
	, [ApplicationName]
	, [Realm]
	, [ObjectSecurity]
	, [FieldLevelSecurity]
	, [OwnerRole]
	, [ApplicationType]
	, [UseRealmRole]
    FROM
	[dbo].[ApplicationDefination]
    WHERE 
	 ([ApplicationKey] = @ApplicationKey OR @ApplicationKey IS NULL)
	AND ([ApplicationName] = @ApplicationName OR @ApplicationName IS NULL)
	AND ([Realm] = @Realm OR @Realm IS NULL)
	AND ([ObjectSecurity] = @ObjectSecurity OR @ObjectSecurity IS NULL)
	AND ([FieldLevelSecurity] = @FieldLevelSecurity OR @FieldLevelSecurity IS NULL)
	AND ([OwnerRole] = @OwnerRole OR @OwnerRole IS NULL)
	AND ([ApplicationType] = @ApplicationType OR @ApplicationType IS NULL)
	AND ([UseRealmRole] = @UseRealmRole OR @UseRealmRole IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ApplicationKey]
	, [ApplicationName]
	, [Realm]
	, [ObjectSecurity]
	, [FieldLevelSecurity]
	, [OwnerRole]
	, [ApplicationType]
	, [UseRealmRole]
    FROM
	[dbo].[ApplicationDefination]
    WHERE 
	 ([ApplicationKey] = @ApplicationKey AND @ApplicationKey is not null)
	OR ([ApplicationName] = @ApplicationName AND @ApplicationName is not null)
	OR ([Realm] = @Realm AND @Realm is not null)
	OR ([ObjectSecurity] = @ObjectSecurity AND @ObjectSecurity is not null)
	OR ([FieldLevelSecurity] = @FieldLevelSecurity AND @FieldLevelSecurity is not null)
	OR ([OwnerRole] = @OwnerRole AND @OwnerRole is not null)
	OR ([ApplicationType] = @ApplicationType AND @ApplicationType is not null)
	OR ([UseRealmRole] = @UseRealmRole AND @UseRealmRole is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspApplicationDefination_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ApplicationDefination table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ApplicationKey] uniqueidentifier 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [ApplicationKey] )
				SELECT TOP {3} [ApplicationKey]
				FROM [dbo].[ApplicationDefination] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[ApplicationKey], O.[ApplicationName], O.[Realm], O.[ObjectSecurity], O.[FieldLevelSecurity], O.[OwnerRole], O.[ApplicationType], O.[UseRealmRole]
				FROM
				    [dbo].[ApplicationDefination] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[ApplicationKey] = PageIndex.[ApplicationKey]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[ApplicationDefination] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspApplicationRoleMapping_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the ApplicationRoleMapping table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[RoleMappingID],
					[ApplicationKey],
					[RoleName],
					[RealmGroupName]
				FROM
					[dbo].[ApplicationRoleMapping]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspApplicationRoleMapping_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ApplicationRoleMapping table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [RoleMappingID] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([RoleMappingID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [RoleMappingID]'
				SET @SQL = @SQL + ' FROM [dbo].[ApplicationRoleMapping]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[RoleMappingID], O.[ApplicationKey], O.[RoleName], O.[RealmGroupName]
				FROM
				    [dbo].[ApplicationRoleMapping] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[RoleMappingID] = PageIndex.[RoleMappingID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[ApplicationRoleMapping]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspApplicationRoleMapping_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the ApplicationRoleMapping table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RoleMappingId" type="int" direction="Output" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@RealmGroupName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[ApplicationRoleMapping]
					(
					[ApplicationKey]
					,[RoleName]
					,[RealmGroupName]
					)
				VALUES
					(
					@ApplicationKey
					,@RoleName
					,@RealmGroupName
					)
				
				-- Get the identity value
				SET @RoleMappingId = SCOPE_IDENTITY()
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationRoleMapping_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the ApplicationRoleMapping table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RoleMappingId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@RealmGroupName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[ApplicationRoleMapping]
				SET
					[ApplicationKey] = @ApplicationKey
					,[RoleName] = @RoleName
					,[RealmGroupName] = @RealmGroupName
				WHERE
[RoleMappingID] = @RoleMappingId 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationRoleMapping_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the ApplicationRoleMapping table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RoleMappingId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[ApplicationRoleMapping] WITH (ROWLOCK) 
				WHERE
					[RoleMappingID] = @RoleMappingId
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationRoleMapping_GetByApplicationKey" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ApplicationRoleMapping table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[RoleMappingID],
					[ApplicationKey],
					[RoleName],
					[RealmGroupName]
				FROM
					[dbo].[ApplicationRoleMapping]
				WHERE
					[ApplicationKey] = @ApplicationKey
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspApplicationRoleMapping_GetByRoleMappingId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ApplicationRoleMapping table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@RoleMappingId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[RoleMappingID],
					[ApplicationKey],
					[RoleName],
					[RealmGroupName]
				FROM
					[dbo].[ApplicationRoleMapping]
				WHERE
					[RoleMappingID] = @RoleMappingId
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspApplicationRoleMapping_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the ApplicationRoleMapping table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@RoleMappingId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@RealmGroupName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [RoleMappingID]
	, [ApplicationKey]
	, [RoleName]
	, [RealmGroupName]
    FROM
	[dbo].[ApplicationRoleMapping]
    WHERE 
	 ([RoleMappingID] = @RoleMappingId OR @RoleMappingId IS NULL)
	AND ([ApplicationKey] = @ApplicationKey OR @ApplicationKey IS NULL)
	AND ([RoleName] = @RoleName OR @RoleName IS NULL)
	AND ([RealmGroupName] = @RealmGroupName OR @RealmGroupName IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [RoleMappingID]
	, [ApplicationKey]
	, [RoleName]
	, [RealmGroupName]
    FROM
	[dbo].[ApplicationRoleMapping]
    WHERE 
	 ([RoleMappingID] = @RoleMappingId AND @RoleMappingId is not null)
	OR ([ApplicationKey] = @ApplicationKey AND @ApplicationKey is not null)
	OR ([RoleName] = @RoleName AND @RoleName is not null)
	OR ([RealmGroupName] = @RealmGroupName AND @RealmGroupName is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspApplicationRoleMapping_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ApplicationRoleMapping table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [RoleMappingID] int 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [RoleMappingID] )
				SELECT TOP {3} [RoleMappingID]
				FROM [dbo].[ApplicationRoleMapping] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[RoleMappingID], O.[ApplicationKey], O.[RoleName], O.[RealmGroupName]
				FROM
				    [dbo].[ApplicationRoleMapping] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[RoleMappingID] = PageIndex.[RoleMappingID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[ApplicationRoleMapping] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspFieldACL_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the FieldACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[FieldACLID],
					[FieldID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowUpdate],
					[All_AllowRead],
					[All_AllowUpdate],
					[Added]
				FROM
					[dbo].[FieldACL]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspFieldACL_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the FieldACL table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [FieldACLID] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([FieldACLID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [FieldACLID]'
				SET @SQL = @SQL + ' FROM [dbo].[FieldACL]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[FieldACLID], O.[FieldID], O.[RoleName], O.[Own_AllowRead], O.[Own_AllowUpdate], O.[All_AllowRead], O.[All_AllowUpdate], O.[Added]
				FROM
				    [dbo].[FieldACL] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[FieldACLID] = PageIndex.[FieldACLID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[FieldACL]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspFieldACL_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the FieldACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldAclid" type="int" direction="Output" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[FieldACL]
					(
					[FieldID]
					,[RoleName]
					,[Own_AllowRead]
					,[Own_AllowUpdate]
					,[All_AllowRead]
					,[All_AllowUpdate]
					,[Added]
					)
				VALUES
					(
					@FieldId
					,@RoleName
					,@OwnAllowRead
					,@OwnAllowUpdate
					,@AllAllowRead
					,@AllAllowUpdate
					,@Added
					)
				
				-- Get the identity value
				SET @FieldAclid = SCOPE_IDENTITY()
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldACL_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the FieldACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[FieldACL]
				SET
					[FieldID] = @FieldId
					,[RoleName] = @RoleName
					,[Own_AllowRead] = @OwnAllowRead
					,[Own_AllowUpdate] = @OwnAllowUpdate
					,[All_AllowRead] = @AllAllowRead
					,[All_AllowUpdate] = @AllAllowUpdate
					,[Added] = @Added
				WHERE
[FieldACLID] = @FieldAclid 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldACL_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the FieldACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[FieldACL] WITH (ROWLOCK) 
				WHERE
					[FieldACLID] = @FieldAclid
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldACL_GetByFieldId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the FieldACL table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[FieldACLID],
					[FieldID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowUpdate],
					[All_AllowRead],
					[All_AllowUpdate],
					[Added]
				FROM
					[dbo].[FieldACL]
				WHERE
					[FieldID] = @FieldId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldACL_GetByFieldAclid" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the FieldACL table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[FieldACLID],
					[FieldID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowUpdate],
					[All_AllowRead],
					[All_AllowUpdate],
					[Added]
				FROM
					[dbo].[FieldACL]
				WHERE
					[FieldACLID] = @FieldAclid
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspFieldACL_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the FieldACL table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [FieldACLID]
	, [FieldID]
	, [RoleName]
	, [Own_AllowRead]
	, [Own_AllowUpdate]
	, [All_AllowRead]
	, [All_AllowUpdate]
	, [Added]
    FROM
	[dbo].[FieldACL]
    WHERE 
	 ([FieldACLID] = @FieldAclid OR @FieldAclid IS NULL)
	AND ([FieldID] = @FieldId OR @FieldId IS NULL)
	AND ([RoleName] = @RoleName OR @RoleName IS NULL)
	AND ([Own_AllowRead] = @OwnAllowRead OR @OwnAllowRead IS NULL)
	AND ([Own_AllowUpdate] = @OwnAllowUpdate OR @OwnAllowUpdate IS NULL)
	AND ([All_AllowRead] = @AllAllowRead OR @AllAllowRead IS NULL)
	AND ([All_AllowUpdate] = @AllAllowUpdate OR @AllAllowUpdate IS NULL)
	AND ([Added] = @Added OR @Added IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [FieldACLID]
	, [FieldID]
	, [RoleName]
	, [Own_AllowRead]
	, [Own_AllowUpdate]
	, [All_AllowRead]
	, [All_AllowUpdate]
	, [Added]
    FROM
	[dbo].[FieldACL]
    WHERE 
	 ([FieldACLID] = @FieldAclid AND @FieldAclid is not null)
	OR ([FieldID] = @FieldId AND @FieldId is not null)
	OR ([RoleName] = @RoleName AND @RoleName is not null)
	OR ([Own_AllowRead] = @OwnAllowRead AND @OwnAllowRead is not null)
	OR ([Own_AllowUpdate] = @OwnAllowUpdate AND @OwnAllowUpdate is not null)
	OR ([All_AllowRead] = @AllAllowRead AND @AllAllowRead is not null)
	OR ([All_AllowUpdate] = @AllAllowUpdate AND @AllAllowUpdate is not null)
	OR ([Added] = @Added AND @Added is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspFieldACL_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the FieldACL table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [FieldACLID] int 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [FieldACLID] )
				SELECT TOP {3} [FieldACLID]
				FROM [dbo].[FieldACL] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[FieldACLID], O.[FieldID], O.[RoleName], O.[Own_AllowRead], O.[Own_AllowUpdate], O.[All_AllowRead], O.[All_AllowUpdate], O.[Added]
				FROM
				    [dbo].[FieldACL] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[FieldACLID] = PageIndex.[FieldACLID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[FieldACL] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspUserProfileData_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the UserProfileData table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[ProfileDataID],
					[UserName],
					[ApplicationKey],
					[ProfileData],
					[LastUpdated]
				FROM
					[dbo].[UserProfileData]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspUserProfileData_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the UserProfileData table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ProfileDataID] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([ProfileDataID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [ProfileDataID]'
				SET @SQL = @SQL + ' FROM [dbo].[UserProfileData]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[ProfileDataID], O.[UserName], O.[ApplicationKey], O.[ProfileData], O.[LastUpdated]
				FROM
				    [dbo].[UserProfileData] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[ProfileDataID] = PageIndex.[ProfileDataID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[UserProfileData]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspUserProfileData_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the UserProfileData table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ProfileDataId" type="int" direction="Output" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ProfileData" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault=""/>
				<parameter name="@LastUpdated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[UserProfileData]
					(
					[UserName]
					,[ApplicationKey]
					,[ProfileData]
					,[LastUpdated]
					)
				VALUES
					(
					@UserName
					,@ApplicationKey
					,@ProfileData
					,@LastUpdated
					)
				
				-- Get the identity value
				SET @ProfileDataId = SCOPE_IDENTITY()
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspUserProfileData_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the UserProfileData table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ProfileDataId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ProfileData" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault=""/>
				<parameter name="@LastUpdated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[UserProfileData]
				SET
					[UserName] = @UserName
					,[ApplicationKey] = @ApplicationKey
					,[ProfileData] = @ProfileData
					,[LastUpdated] = @LastUpdated
				WHERE
[ProfileDataID] = @ProfileDataId 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspUserProfileData_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the UserProfileData table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ProfileDataId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[UserProfileData] WITH (ROWLOCK) 
				WHERE
					[ProfileDataID] = @ProfileDataId
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspUserProfileData_GetByApplicationKey" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserProfileData table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[ProfileDataID],
					[UserName],
					[ApplicationKey],
					[ProfileData],
					[LastUpdated]
				FROM
					[dbo].[UserProfileData]
				WHERE
					[ApplicationKey] = @ApplicationKey
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspUserProfileData_GetByProfileDataId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserProfileData table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ProfileDataId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[ProfileDataID],
					[UserName],
					[ApplicationKey],
					[ProfileData],
					[LastUpdated]
				FROM
					[dbo].[UserProfileData]
				WHERE
					[ProfileDataID] = @ProfileDataId
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspUserProfileData_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the UserProfileData table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@ProfileDataId" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@ProfileData" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault="null"/>
				<parameter name="@LastUpdated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ProfileDataID]
	, [UserName]
	, [ApplicationKey]
	, [ProfileData]
	, [LastUpdated]
    FROM
	[dbo].[UserProfileData]
    WHERE 
	 ([ProfileDataID] = @ProfileDataId OR @ProfileDataId IS NULL)
	AND ([UserName] = @UserName OR @UserName IS NULL)
	AND ([ApplicationKey] = @ApplicationKey OR @ApplicationKey IS NULL)
	AND ([ProfileData] = @ProfileData OR @ProfileData IS NULL)
	AND ([LastUpdated] = @LastUpdated OR @LastUpdated IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ProfileDataID]
	, [UserName]
	, [ApplicationKey]
	, [ProfileData]
	, [LastUpdated]
    FROM
	[dbo].[UserProfileData]
    WHERE 
	 ([ProfileDataID] = @ProfileDataId AND @ProfileDataId is not null)
	OR ([UserName] = @UserName AND @UserName is not null)
	OR ([ApplicationKey] = @ApplicationKey AND @ApplicationKey is not null)
	OR ([ProfileData] = @ProfileData AND @ProfileData is not null)
	OR ([LastUpdated] = @LastUpdated AND @LastUpdated is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspUserProfileData_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the UserProfileData table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ProfileDataID] int 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [ProfileDataID] )
				SELECT TOP {3} [ProfileDataID]
				FROM [dbo].[UserProfileData] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[ProfileDataID], O.[UserName], O.[ApplicationKey], O.[ProfileData], O.[LastUpdated]
				FROM
				    [dbo].[UserProfileData] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[ProfileDataID] = PageIndex.[ProfileDataID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[UserProfileData] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
				
		<procedure owner="dbo" name="usp_UserProfileData_GetByApplicationUser"  skip="true">
			<comment><![CDATA[-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
]]></comment>
			<parameters>
				<parameter name="@App" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="1024" precision="0" scale="0" param="(1024)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT * from UserProfileData 
		where ApplicationKey = @App and UserName = @userName
END

			]]></body>
					</procedure>
		
		<procedure owner="dbo" name="uspFieldDefinition_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the FieldDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[FieldID],
					[ObjectID],
					[FieldName],
					[FieldDataType],
					[IsRequired],
					[SecurityEnabled]
				FROM
					[dbo].[FieldDefinition]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspFieldDefinition_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the FieldDefinition table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [FieldID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([FieldID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [FieldID]'
				SET @SQL = @SQL + ' FROM [dbo].[FieldDefinition]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[FieldID], O.[ObjectID], O.[FieldName], O.[FieldDataType], O.[IsRequired], O.[SecurityEnabled]
				FROM
				    [dbo].[FieldDefinition] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[FieldID] = PageIndex.[FieldID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[FieldDefinition]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspFieldDefinition_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the FieldDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@FieldDataType" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@IsRequired" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@SecurityEnabled" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[FieldDefinition]
					(
					[FieldID]
					,[ObjectID]
					,[FieldName]
					,[FieldDataType]
					,[IsRequired]
					,[SecurityEnabled]
					)
				VALUES
					(
					@FieldId
					,@ObjectId
					,@FieldName
					,@FieldDataType
					,@IsRequired
					,@SecurityEnabled
					)
				
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldDefinition_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the FieldDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@OriginalFieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@FieldDataType" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@IsRequired" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@SecurityEnabled" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[FieldDefinition]
				SET
					[FieldID] = @FieldId
					,[ObjectID] = @ObjectId
					,[FieldName] = @FieldName
					,[FieldDataType] = @FieldDataType
					,[IsRequired] = @IsRequired
					,[SecurityEnabled] = @SecurityEnabled
				WHERE
[FieldID] = @OriginalFieldId 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldDefinition_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the FieldDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[FieldDefinition] WITH (ROWLOCK) 
				WHERE
					[FieldID] = @FieldId
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldDefinition_GetByObjectId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the FieldDefinition table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[FieldID],
					[ObjectID],
					[FieldName],
					[FieldDataType],
					[IsRequired],
					[SecurityEnabled]
				FROM
					[dbo].[FieldDefinition]
				WHERE
					[ObjectID] = @ObjectId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspFieldDefinition_GetByFieldId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the FieldDefinition table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[FieldID],
					[ObjectID],
					[FieldName],
					[FieldDataType],
					[IsRequired],
					[SecurityEnabled]
				FROM
					[dbo].[FieldDefinition]
				WHERE
					[FieldID] = @FieldId
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspFieldDefinition_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the FieldDefinition table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@FieldDataType" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@IsRequired" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@SecurityEnabled" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [FieldID]
	, [ObjectID]
	, [FieldName]
	, [FieldDataType]
	, [IsRequired]
	, [SecurityEnabled]
    FROM
	[dbo].[FieldDefinition]
    WHERE 
	 ([FieldID] = @FieldId OR @FieldId IS NULL)
	AND ([ObjectID] = @ObjectId OR @ObjectId IS NULL)
	AND ([FieldName] = @FieldName OR @FieldName IS NULL)
	AND ([FieldDataType] = @FieldDataType OR @FieldDataType IS NULL)
	AND ([IsRequired] = @IsRequired OR @IsRequired IS NULL)
	AND ([SecurityEnabled] = @SecurityEnabled OR @SecurityEnabled IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [FieldID]
	, [ObjectID]
	, [FieldName]
	, [FieldDataType]
	, [IsRequired]
	, [SecurityEnabled]
    FROM
	[dbo].[FieldDefinition]
    WHERE 
	 ([FieldID] = @FieldId AND @FieldId is not null)
	OR ([ObjectID] = @ObjectId AND @ObjectId is not null)
	OR ([FieldName] = @FieldName AND @FieldName is not null)
	OR ([FieldDataType] = @FieldDataType AND @FieldDataType is not null)
	OR ([IsRequired] = @IsRequired AND @IsRequired is not null)
	OR ([SecurityEnabled] = @SecurityEnabled AND @SecurityEnabled is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspFieldDefinition_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the FieldDefinition table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [FieldID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [FieldID] )
				SELECT TOP {3} [FieldID]
				FROM [dbo].[FieldDefinition] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[FieldID], O.[ObjectID], O.[FieldName], O.[FieldDataType], O.[IsRequired], O.[SecurityEnabled]
				FROM
				    [dbo].[FieldDefinition] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[FieldID] = PageIndex.[FieldID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[FieldDefinition] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspSecurityToken_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the SecurityToken table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[TokenKey],
					[Realm],
					[SourceApplication],
					[TokenCreated],
					[UserName]
				FROM
					[dbo].[SecurityToken]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspSecurityToken_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the SecurityToken table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [TokenKey] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([TokenKey])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [TokenKey]'
				SET @SQL = @SQL + ' FROM [dbo].[SecurityToken]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[TokenKey], O.[Realm], O.[SourceApplication], O.[TokenCreated], O.[UserName]
				FROM
				    [dbo].[SecurityToken] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[TokenKey] = PageIndex.[TokenKey]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[SecurityToken]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspSecurityToken_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the SecurityToken table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@TokenKey" type="uniqueidentifier" direction="Output" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@SourceApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@TokenCreated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="1024" precision="0" scale="0" param="(1024)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[SecurityToken]
					(
					[TokenKey]
					,[Realm]
					,[SourceApplication]
					,[TokenCreated]
					,[UserName]
					)
				VALUES
					(
					@TokenKey
					,@Realm
					,@SourceApplication
					,@TokenCreated
					,@UserName
					)
				
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the SecurityToken table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@TokenKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@OriginalTokenKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@SourceApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@TokenCreated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="1024" precision="0" scale="0" param="(1024)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[SecurityToken]
				SET
					[TokenKey] = @TokenKey
					,[Realm] = @Realm
					,[SourceApplication] = @SourceApplication
					,[TokenCreated] = @TokenCreated
					,[UserName] = @UserName
				WHERE
[TokenKey] = @OriginalTokenKey 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the SecurityToken table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@TokenKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[SecurityToken] WITH (ROWLOCK) 
				WHERE
					[TokenKey] = @TokenKey
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_GetBySourceApplication" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the SecurityToken table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SourceApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[TokenKey],
					[Realm],
					[SourceApplication],
					[TokenCreated],
					[UserName]
				FROM
					[dbo].[SecurityToken]
				WHERE
					[SourceApplication] = @SourceApplication
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_GetByRealm" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the SecurityToken table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[TokenKey],
					[Realm],
					[SourceApplication],
					[TokenCreated],
					[UserName]
				FROM
					[dbo].[SecurityToken]
				WHERE
					[Realm] = @Realm
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_GetByTokenKey" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the SecurityToken table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@TokenKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[TokenKey],
					[Realm],
					[SourceApplication],
					[TokenCreated],
					[UserName]
				FROM
					[dbo].[SecurityToken]
				WHERE
					[TokenKey] = @TokenKey
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspSecurityToken_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the SecurityToken table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@TokenKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@Realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@SourceApplication" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@TokenCreated" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault="null"/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="1024" precision="0" scale="0" param="(1024)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [TokenKey]
	, [Realm]
	, [SourceApplication]
	, [TokenCreated]
	, [UserName]
    FROM
	[dbo].[SecurityToken]
    WHERE 
	 ([TokenKey] = @TokenKey OR @TokenKey IS NULL)
	AND ([Realm] = @Realm OR @Realm IS NULL)
	AND ([SourceApplication] = @SourceApplication OR @SourceApplication IS NULL)
	AND ([TokenCreated] = @TokenCreated OR @TokenCreated IS NULL)
	AND ([UserName] = @UserName OR @UserName IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [TokenKey]
	, [Realm]
	, [SourceApplication]
	, [TokenCreated]
	, [UserName]
    FROM
	[dbo].[SecurityToken]
    WHERE 
	 ([TokenKey] = @TokenKey AND @TokenKey is not null)
	OR ([Realm] = @Realm AND @Realm is not null)
	OR ([SourceApplication] = @SourceApplication AND @SourceApplication is not null)
	OR ([TokenCreated] = @TokenCreated AND @TokenCreated is not null)
	OR ([UserName] = @UserName AND @UserName is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspSecurityToken_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the SecurityToken table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [TokenKey] uniqueidentifier 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [TokenKey] )
				SELECT TOP {3} [TokenKey]
				FROM [dbo].[SecurityToken] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[TokenKey], O.[Realm], O.[SourceApplication], O.[TokenCreated], O.[UserName]
				FROM
				    [dbo].[SecurityToken] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[TokenKey] = PageIndex.[TokenKey]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[SecurityToken] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
				
		<procedure owner="dbo" name="usp_SecurityToken_FindByUser"  skip="true">
			<comment><![CDATA[-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
]]></comment>
			<parameters>
				<parameter name="@realm" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@sourceApp" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@UserName" type="nvarchar" direction="Input" size="1024" precision="0" scale="0" param="(1024)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT * from SecurityToken where Realm = @realm and SourceApplication = @sourceApp and UserName = @userName
END

			]]></body>
					</procedure>
		
		<procedure owner="dbo" name="uspObjectDefinition_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the ObjectDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[ObjectID],
					[ObjectName],
					[ApplicationKey],
					[SchemaDefinition],
					[OwnerRole],
					[Added],
					[Audited],
					[FieldLevelSecurity],
					[ObjectCategory]
				FROM
					[dbo].[ObjectDefinition]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspObjectDefinition_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ObjectDefinition table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ObjectID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([ObjectID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [ObjectID]'
				SET @SQL = @SQL + ' FROM [dbo].[ObjectDefinition]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[ObjectID], O.[ObjectName], O.[ApplicationKey], O.[SchemaDefinition], O.[OwnerRole], O.[Added], O.[Audited], O.[FieldLevelSecurity], O.[ObjectCategory]
				FROM
				    [dbo].[ObjectDefinition] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[ObjectID] = PageIndex.[ObjectID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[ObjectDefinition]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspObjectDefinition_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the ObjectDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@SchemaDefinition" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault=""/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
				<parameter name="@Audited" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectCategory" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[ObjectDefinition]
					(
					[ObjectID]
					,[ObjectName]
					,[ApplicationKey]
					,[SchemaDefinition]
					,[OwnerRole]
					,[Added]
					,[Audited]
					,[FieldLevelSecurity]
					,[ObjectCategory]
					)
				VALUES
					(
					@ObjectId
					,@ObjectName
					,@ApplicationKey
					,@SchemaDefinition
					,@OwnerRole
					,@Added
					,@Audited
					,@FieldLevelSecurity
					,@ObjectCategory
					)
				
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectDefinition_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the ObjectDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@OriginalObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@SchemaDefinition" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault=""/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
				<parameter name="@Audited" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectCategory" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[ObjectDefinition]
				SET
					[ObjectID] = @ObjectId
					,[ObjectName] = @ObjectName
					,[ApplicationKey] = @ApplicationKey
					,[SchemaDefinition] = @SchemaDefinition
					,[OwnerRole] = @OwnerRole
					,[Added] = @Added
					,[Audited] = @Audited
					,[FieldLevelSecurity] = @FieldLevelSecurity
					,[ObjectCategory] = @ObjectCategory
				WHERE
[ObjectID] = @OriginalObjectId 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectDefinition_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the ObjectDefinition table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[ObjectDefinition] WITH (ROWLOCK) 
				WHERE
					[ObjectID] = @ObjectId
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectDefinition_GetByApplicationKey" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ObjectDefinition table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[ObjectID],
					[ObjectName],
					[ApplicationKey],
					[SchemaDefinition],
					[OwnerRole],
					[Added],
					[Audited],
					[FieldLevelSecurity],
					[ObjectCategory]
				FROM
					[dbo].[ObjectDefinition]
				WHERE
					[ApplicationKey] = @ApplicationKey
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectDefinition_GetByObjectId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ObjectDefinition table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[ObjectID],
					[ObjectName],
					[ApplicationKey],
					[SchemaDefinition],
					[OwnerRole],
					[Added],
					[Audited],
					[FieldLevelSecurity],
					[ObjectCategory]
				FROM
					[dbo].[ObjectDefinition]
				WHERE
					[ObjectID] = @ObjectId
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspObjectDefinition_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the ObjectDefinition table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@ApplicationKey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@SchemaDefinition" type="nvarchar" direction="Input" size="-1" precision="0" scale="0" param="(MAX)" nulldefault="null"/>
				<parameter name="@OwnerRole" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault="null"/>
				<parameter name="@Audited" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@FieldLevelSecurity" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectCategory" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ObjectID]
	, [ObjectName]
	, [ApplicationKey]
	, [SchemaDefinition]
	, [OwnerRole]
	, [Added]
	, [Audited]
	, [FieldLevelSecurity]
	, [ObjectCategory]
    FROM
	[dbo].[ObjectDefinition]
    WHERE 
	 ([ObjectID] = @ObjectId OR @ObjectId IS NULL)
	AND ([ObjectName] = @ObjectName OR @ObjectName IS NULL)
	AND ([ApplicationKey] = @ApplicationKey OR @ApplicationKey IS NULL)
	AND ([SchemaDefinition] = @SchemaDefinition OR @SchemaDefinition IS NULL)
	AND ([OwnerRole] = @OwnerRole OR @OwnerRole IS NULL)
	AND ([Added] = @Added OR @Added IS NULL)
	AND ([Audited] = @Audited OR @Audited IS NULL)
	AND ([FieldLevelSecurity] = @FieldLevelSecurity OR @FieldLevelSecurity IS NULL)
	AND ([ObjectCategory] = @ObjectCategory OR @ObjectCategory IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ObjectID]
	, [ObjectName]
	, [ApplicationKey]
	, [SchemaDefinition]
	, [OwnerRole]
	, [Added]
	, [Audited]
	, [FieldLevelSecurity]
	, [ObjectCategory]
    FROM
	[dbo].[ObjectDefinition]
    WHERE 
	 ([ObjectID] = @ObjectId AND @ObjectId is not null)
	OR ([ObjectName] = @ObjectName AND @ObjectName is not null)
	OR ([ApplicationKey] = @ApplicationKey AND @ApplicationKey is not null)
	OR ([SchemaDefinition] = @SchemaDefinition AND @SchemaDefinition is not null)
	OR ([OwnerRole] = @OwnerRole AND @OwnerRole is not null)
	OR ([Added] = @Added AND @Added is not null)
	OR ([Audited] = @Audited AND @Audited is not null)
	OR ([FieldLevelSecurity] = @FieldLevelSecurity AND @FieldLevelSecurity is not null)
	OR ([ObjectCategory] = @ObjectCategory AND @ObjectCategory is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspObjectDefinition_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ObjectDefinition table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ObjectID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [ObjectID] )
				SELECT TOP {3} [ObjectID]
				FROM [dbo].[ObjectDefinition] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[ObjectID], O.[ObjectName], O.[ApplicationKey], O.[SchemaDefinition], O.[OwnerRole], O.[Added], O.[Audited], O.[FieldLevelSecurity], O.[ObjectCategory]
				FROM
				    [dbo].[ObjectDefinition] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[ObjectID] = PageIndex.[ObjectID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[ObjectDefinition] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
				
		<procedure owner="dbo" name="usp_ObjectDefinition_GetByCategory"  skip="true">
			<comment><![CDATA[]]></comment>
			<parameters>
				<parameter name="@applicationkey" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@category" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				

	set nocount on
	select * from ObjectDefinition where ApplicationKey = @applicationkey and ObjectCategory = @category
			]]></body>
					</procedure>
		
		<procedure owner="dbo" name="uspObjectACL_Get_List" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the ObjectACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				SELECT
					[ObjectACLID],
					[ObjectID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowCreate],
					[Own_AllowUpdate],
					[Own_AllowDelete],
					[All_AllowRead],
					[All_AllowCreate],
					[All_AllowUpdate],
					[All_AllowDelete],
					[Added]
				FROM
					[dbo].[ObjectACL]
					
				SELECT @@ROWCOUNT
			]]></body>
		</procedure>
		
		
		<procedure owner="dbo" name="uspObjectACL_GetPaged" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ObjectACL table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@WhereClause" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)" />
				<parameter name="@OrderBy" type="varchar" direction="Input" size="2000" precision="0" scale="0" param="(2000)"/>
				<parameter name="@PageIndex" type="int" direction="Input" size="0" precision="10" scale="0" />
				<parameter name="@PageSize" type="int" direction="Input" size="0" precision="10" scale="0" /> 
			</parameters>
			<body><![CDATA[
				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ObjectACLID] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([ObjectACLID])'
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' [ObjectACLID]'
				SET @SQL = @SQL + ' FROM [dbo].[ObjectACL]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Return paged results
				SELECT O.[ObjectACLID], O.[ObjectID], O.[RoleName], O.[Own_AllowRead], O.[Own_AllowCreate], O.[Own_AllowUpdate], O.[Own_AllowDelete], O.[All_AllowRead], O.[All_AllowCreate], O.[All_AllowUpdate], O.[All_AllowDelete], O.[Added]
				FROM
				    [dbo].[ObjectACL] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[ObjectACLID] = PageIndex.[ObjectACLID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[ObjectACL]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			]]></body>
		</procedure>
		
		<procedure owner="dbo" name="uspObjectACL_Insert" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the ObjectACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectAclid" type="int" direction="Output" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				INSERT INTO [dbo].[ObjectACL]
					(
					[ObjectID]
					,[RoleName]
					,[Own_AllowRead]
					,[Own_AllowCreate]
					,[Own_AllowUpdate]
					,[Own_AllowDelete]
					,[All_AllowRead]
					,[All_AllowCreate]
					,[All_AllowUpdate]
					,[All_AllowDelete]
					,[Added]
					)
				VALUES
					(
					@ObjectId
					,@RoleName
					,@OwnAllowRead
					,@OwnAllowCreate
					,@OwnAllowUpdate
					,@OwnAllowDelete
					,@AllAllowRead
					,@AllAllowCreate
					,@AllAllowUpdate
					,@AllAllowDelete
					,@Added
					)
				
				-- Get the identity value
				SET @ObjectAclid = SCOPE_IDENTITY()
									
							
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectACL_Update" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the ObjectACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault=""/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@OwnAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@AllAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault=""/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[ObjectACL]
				SET
					[ObjectID] = @ObjectId
					,[RoleName] = @RoleName
					,[Own_AllowRead] = @OwnAllowRead
					,[Own_AllowCreate] = @OwnAllowCreate
					,[Own_AllowUpdate] = @OwnAllowUpdate
					,[Own_AllowDelete] = @OwnAllowDelete
					,[All_AllowRead] = @AllAllowRead
					,[All_AllowCreate] = @AllAllowCreate
					,[All_AllowUpdate] = @AllAllowUpdate
					,[All_AllowDelete] = @AllAllowDelete
					,[Added] = @Added
				WHERE
[ObjectACLID] = @ObjectAclid 
				
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectACL_Delete" grant="">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the ObjectACL table
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				DELETE FROM [dbo].[ObjectACL] WITH (ROWLOCK) 
				WHERE
					[ObjectACLID] = @ObjectAclid
					
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectACL_GetByObjectId" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ObjectACL table through a foreign key
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SET ANSI_NULLS OFF
				
				SELECT
					[ObjectACLID],
					[ObjectID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowCreate],
					[Own_AllowUpdate],
					[Own_AllowDelete],
					[All_AllowRead],
					[All_AllowCreate],
					[All_AllowUpdate],
					[All_AllowDelete],
					[Added]
				FROM
					[dbo].[ObjectACL]
				WHERE
					[ObjectID] = @ObjectId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			]]></body>
		</procedure>
		<procedure owner="dbo" name="uspObjectACL_GetByObjectAclid" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the ObjectACL table through an index
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@ObjectAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault=""/>
			</parameters>
			<body><![CDATA[
				SELECT
					[ObjectACLID],
					[ObjectID],
					[RoleName],
					[Own_AllowRead],
					[Own_AllowCreate],
					[Own_AllowUpdate],
					[Own_AllowDelete],
					[All_AllowRead],
					[All_AllowCreate],
					[All_AllowUpdate],
					[All_AllowDelete],
					[Added]
				FROM
					[dbo].[ObjectACL]
				WHERE
					[ObjectACLID] = @ObjectAclid
				SELECT @@ROWCOUNT
					
			]]></body>
			
		</procedure>
		<procedure owner="dbo" name="uspObjectACL_Find" >
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the ObjectACL table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters>
				<parameter name="@SearchUsingOR" type="bit" direction="Input" size="0" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectAclid" type="int" direction="Input" size="4" precision="10" scale="0" param="" nulldefault="null"/>
				<parameter name="@ObjectId" type="uniqueidentifier" direction="Input" size="16" precision="0" scale="0" param="" nulldefault="null"/>
				<parameter name="@RoleName" type="nvarchar" direction="Input" size="50" precision="0" scale="0" param="(50)" nulldefault="null"/>
				<parameter name="@OwnAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@OwnAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@OwnAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@OwnAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowRead" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowCreate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowUpdate" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@AllAllowDelete" type="bit" direction="Input" size="1" precision="1" scale="0" param="" nulldefault="null"/>
				<parameter name="@Added" type="datetime" direction="Input" size="8" precision="23" scale="3" param="" nulldefault="null"/>
			</parameters>
			<body><![CDATA[
				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ObjectACLID]
	, [ObjectID]
	, [RoleName]
	, [Own_AllowRead]
	, [Own_AllowCreate]
	, [Own_AllowUpdate]
	, [Own_AllowDelete]
	, [All_AllowRead]
	, [All_AllowCreate]
	, [All_AllowUpdate]
	, [All_AllowDelete]
	, [Added]
    FROM
	[dbo].[ObjectACL]
    WHERE 
	 ([ObjectACLID] = @ObjectAclid OR @ObjectAclid IS NULL)
	AND ([ObjectID] = @ObjectId OR @ObjectId IS NULL)
	AND ([RoleName] = @RoleName OR @RoleName IS NULL)
	AND ([Own_AllowRead] = @OwnAllowRead OR @OwnAllowRead IS NULL)
	AND ([Own_AllowCreate] = @OwnAllowCreate OR @OwnAllowCreate IS NULL)
	AND ([Own_AllowUpdate] = @OwnAllowUpdate OR @OwnAllowUpdate IS NULL)
	AND ([Own_AllowDelete] = @OwnAllowDelete OR @OwnAllowDelete IS NULL)
	AND ([All_AllowRead] = @AllAllowRead OR @AllAllowRead IS NULL)
	AND ([All_AllowCreate] = @AllAllowCreate OR @AllAllowCreate IS NULL)
	AND ([All_AllowUpdate] = @AllAllowUpdate OR @AllAllowUpdate IS NULL)
	AND ([All_AllowDelete] = @AllAllowDelete OR @AllAllowDelete IS NULL)
	AND ([Added] = @Added OR @Added IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ObjectACLID]
	, [ObjectID]
	, [RoleName]
	, [Own_AllowRead]
	, [Own_AllowCreate]
	, [Own_AllowUpdate]
	, [Own_AllowDelete]
	, [All_AllowRead]
	, [All_AllowCreate]
	, [All_AllowUpdate]
	, [All_AllowDelete]
	, [Added]
    FROM
	[dbo].[ObjectACL]
    WHERE 
	 ([ObjectACLID] = @ObjectAclid AND @ObjectAclid is not null)
	OR ([ObjectID] = @ObjectId AND @ObjectId is not null)
	OR ([RoleName] = @RoleName AND @RoleName is not null)
	OR ([Own_AllowRead] = @OwnAllowRead AND @OwnAllowRead is not null)
	OR ([Own_AllowCreate] = @OwnAllowCreate AND @OwnAllowCreate is not null)
	OR ([Own_AllowUpdate] = @OwnAllowUpdate AND @OwnAllowUpdate is not null)
	OR ([Own_AllowDelete] = @OwnAllowDelete AND @OwnAllowDelete is not null)
	OR ([All_AllowRead] = @AllAllowRead AND @AllAllowRead is not null)
	OR ([All_AllowCreate] = @AllAllowCreate AND @AllAllowCreate is not null)
	OR ([All_AllowUpdate] = @AllAllowUpdate AND @AllAllowUpdate is not null)
	OR ([All_AllowDelete] = @AllAllowDelete AND @AllAllowDelete is not null)
	OR ([Added] = @Added AND @Added is not null)
	SELECT @@ROWCOUNT			
  END
				]]></body>
		</procedure>

		
		<procedure owner="dbo" name="uspObjectACL_Find_Dynamic"  skip="true">
			<comment><![CDATA[/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the ObjectACL table using a dynamically generated query.
----------------------------------------------------------------------------------------------------
*/
]]></comment>
			<parameters/>
			<body><![CDATA[
				
				BEGIN
				
				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ObjectACLID] int 
				)
				
				-- Insert into the temp table
				INSERT INTO #PageIndex ( [ObjectACLID] )
				SELECT TOP {3} [ObjectACLID]
				FROM [dbo].[ObjectACL] {0}
				ORDER BY {1}
				
				-- Return paged results
				SELECT O.[ObjectACLID], O.[ObjectID], O.[RoleName], O.[Own_AllowRead], O.[Own_AllowCreate], O.[Own_AllowUpdate], O.[Own_AllowDelete], O.[All_AllowRead], O.[All_AllowCreate], O.[All_AllowUpdate], O.[All_AllowDelete], O.[Added]
				FROM
				    [dbo].[ObjectACL] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > {2}
				    AND O.[ObjectACLID] = PageIndex.[ObjectACLID]
				ORDER BY
				    PageIndex.IndexId
				

				-- get total count
				SELECT COUNT(*) AS TotalRowCount FROM [dbo].[ObjectACL] {0};
				
				DROP TABLE #PageIndex
				END
			]]></body>
		</procedure>
		
</procedures>
</root>
